package com.clock.web.controller.shop;

import com.clock.common.annotation.Log;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.page.TableDataInfo;
import com.clock.common.enums.BusinessType;

import com.clock.common.utils.poi.ExcelUtil;
import com.clock.shop.domain.ShopComment;
import com.clock.shop.service.IShopCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评论Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/shop/comment")
public class ShopCommentController extends BaseController
{
    @Autowired
    private IShopCommentService shopCommentService;

    /**
     * 查询评论列表
     */
    // @PreAuthorize("@ss.hasPermi('shop:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopComment shopComment)
    {
        startPage();
        List<ShopComment> list = shopCommentService.selectShopCommentList(shopComment);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @PreAuthorize("@ss.hasPermi('shop:comment:export')")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopComment shopComment)
    {
        List<ShopComment> list = shopCommentService.selectShopCommentList(shopComment);
        ExcelUtil<ShopComment> util = new ExcelUtil<ShopComment>(ShopComment.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(shopCommentService.selectShopCommentByCommentId(commentId));
    }

    /**
     * 新增评论
     */
    @PreAuthorize("@ss.hasPermi('shop:comment:add')")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopComment shopComment)
    {
        return toAjax(shopCommentService.insertShopComment(shopComment));
    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('shop:comment:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopComment shopComment)
    {
        return toAjax(shopCommentService.updateShopComment(shopComment));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('shop:comment:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(shopCommentService.deleteShopCommentByCommentIds(commentIds));
    }
}
